home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / TIPS / CENTER.PAS < prev    next >
Pascal/Delphi Source File  |  1991-10-09  |  2KB  |  63 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal for Windows                     }
  4. {   Tips & Techniques Demo Program               }
  5. {   Copyright (c) 1991 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. program Center;
  10.  
  11. {$R Center}
  12.  
  13. uses WinTypes, WinProcs, WObjects;
  14.  
  15. type
  16. TApp = object(TApplication)
  17.   procedure InitMainWindow; virtual;
  18. end;
  19.  
  20. PMyWindow = ^TMyWindow;
  21. TMyWindow = object(TWindow)
  22.   procedure WMLButtonDown(var Message:TMessage);
  23.     virtual wm_LButtonDown;
  24. end;
  25.  
  26. PMyDialog = ^TMyDialog;
  27. TMyDialog = object(TDlgWindow)
  28.    procedure SetupWindow; virtual;
  29. end;
  30.  
  31. procedure TApp.InitMainWindow;
  32. begin
  33.   MainWindow := New(PMyWindow, Init(Nil, 'Center'));
  34. end;
  35.  
  36. procedure TMyDialog.SetupWindow;
  37. var
  38.   MyRect: TRect;
  39.   X, Y: Integer;
  40. begin
  41.   TDlgWindow.SetupWindow;
  42.   X := GetSystemMetrics(SM_CXScreen) div 2;
  43.   Y := GetSystemMetrics(SM_CYScreen) div 2;
  44.   GetWindowRect(HWindow, MyRect);
  45.   with MyRect do
  46.     SetWindowPos(HWindow, 0, x -  ((Right-Left) div 2),
  47.       y - ((Bottom-Top) div 2), MyRect.Right,  MyRect.Bottom,
  48.     swp_NoSize or swp_NoZOrder);
  49. end;
  50.  
  51. procedure TMyWindow.WMLButtonDown(var Message: TMessage);
  52. begin
  53.   Application^.ExecDialog(new(PMyDialog, Init(@Self, 'Center_Me')));
  54. end;
  55.  
  56. var
  57.   App: TApp;
  58. begin
  59.   App.Init('Center');
  60.   App.Run;
  61.   App.Done;
  62. end.
  63.